﻿namespace WMS6.Web.CustomizeReport
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.CustomizeReportServiceRef;
    using WMS6.Web.UserControls;

    public class TNTInOutStockInvRptList : BasePage
    {
        protected Button btnExport;
        protected Button btnList;
        protected Button btnRefresh;
        protected Button btnReSearch;
        protected Button btnSearch;
        protected HtmlForm F16021;
        protected GridView gvInOutStockInvRptList;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdnFrom;
        protected HtmlHead Head1;
        protected Label lblMsg;
        protected Label lblTNTInOutStockInvRptList;
        protected Label lblTotal;
        protected Label lblTotalBeginQty;
        protected Label lblTotalBeginQtyText;
        protected Label lblTotalExpiredQty;
        protected Label lblTotalExpiredQtyText;
        protected Label lblTotalInBoundQty;
        protected Label lblTotalInBoundQtyText;
        protected Label lblTotalInvQty;
        protected Label lblTotalInvQtyText;
        protected Label lblTotalOpenQty;
        protected Label lblTotalOpenQtyText;
        protected Label lblTotalOutBoundQty;
        protected Label lblTotalOutBoundQtyText;
        protected Label lblTotalScrapQty;
        protected Label lblTotalScrapQtyText;
        protected HtmlLink mycss;
        protected Pager PagerFooter;
        protected ScriptManager ScriptManager1;
        private decimal TotalBeginQty;
        private decimal TotalExpiredQty;
        private decimal TotalInBoundQty;
        private decimal TotalInvQty;
        private decimal TotalOpenQty;
        private decimal TotalOutBoundQty;
        private decimal TotalScrapQty;
        protected UpdatePanel up1;

        public void BindData2ShipmentOderRptList(TNTInOutStockInvRptQueryEntity tntInOutStockInvRptQueryEntity)
        {
            this.PagerFooter.CurrentPage = int.Parse(tntInOutStockInvRptQueryEntity.CurrentPage);
            DataSet ds = CustomizeReportServiceClientProxy.GetInstance().GetTNTInOutStockInvRptDataSet(tntInOutStockInvRptQueryEntity);
            base.BindData2GridView(this.gvInOutStockInvRptList, ds);
            if ((ds != null) && (ds.Tables.Count > 1))
            {
                this.PagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                this.PagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            TNTInOutStockInvRptQueryEntity tntInOutStockInvRptQueryEntity = this.GetTNTInOutStockInvRptQueryEntity();
            tntInOutStockInvRptQueryEntity.IsGetAll = true;
            this.hdnActionID.Value = "EXPORT";
            string currentPageIndex = tntInOutStockInvRptQueryEntity.CurrentPage;
            tntInOutStockInvRptQueryEntity.CurrentPage = "0";
            this.gvInOutStockInvRptList.Columns[1].Visible = false;
            this.gvInOutStockInvRptList.AllowSorting = false;
            this.BindData2ShipmentOderRptList(tntInOutStockInvRptQueryEntity);
            this.gvInOutStockInvRptList.ShowFooter = false;
            tntInOutStockInvRptQueryEntity.IsGetAll = false;
            tntInOutStockInvRptQueryEntity.CurrentPage = currentPageIndex;
            this.SetShipmentOrderRptQuery(tntInOutStockInvRptQueryEntity);
            base.Export2Excel("InOutStockInvRpt.xls", this.gvInOutStockInvRptList);
        }

        protected void btnFirst_Click(object sender, EventArgs e)
        {
            TNTInOutStockInvRptQueryEntity tntInOutStockInvRptQueryEntity = this.GetTNTInOutStockInvRptQueryEntity();
            tntInOutStockInvRptQueryEntity.CurrentPage = "0";
            this.BindData2ShipmentOderRptList(tntInOutStockInvRptQueryEntity);
        }

        protected void btnLast_Click(object sender, EventArgs e)
        {
            TNTInOutStockInvRptQueryEntity tntInOutStockInvRptQueryEntity = this.GetTNTInOutStockInvRptQueryEntity();
            tntInOutStockInvRptQueryEntity.CurrentPage = (this.PagerFooter.TotalPages - 1).ToString();
            this.BindData2ShipmentOderRptList(tntInOutStockInvRptQueryEntity);
        }

        protected void btnList_Click(object sender, EventArgs e)
        {
            TNTInOutStockInvRptQueryEntity tntInOutStockInvRptQueryEntity = this.GetTNTInOutStockInvRptQueryEntity();
            tntInOutStockInvRptQueryEntity.OWNER_ID = "";
            tntInOutStockInvRptQueryEntity.START_DATETIME = DateTime.Now.ToString();
            tntInOutStockInvRptQueryEntity.END_DATETIME = "";
            tntInOutStockInvRptQueryEntity.SKU_ID = "";
            tntInOutStockInvRptQueryEntity.SKU_CLASS_ID = "";
            tntInOutStockInvRptQueryEntity.DESCR = "";
            tntInOutStockInvRptQueryEntity.SKU_GROUP = "";
            this.BindData2ShipmentOderRptList(tntInOutStockInvRptQueryEntity);
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            TNTInOutStockInvRptQueryEntity tntInOutStockInvRptQueryEntity = this.GetTNTInOutStockInvRptQueryEntity();
            if (int.Parse(tntInOutStockInvRptQueryEntity.CurrentPage) < (this.PagerFooter.TotalPages - 1))
            {
                tntInOutStockInvRptQueryEntity.CurrentPage = (int.Parse(tntInOutStockInvRptQueryEntity.CurrentPage) + 1).ToString();
                this.BindData2ShipmentOderRptList(tntInOutStockInvRptQueryEntity);
            }
        }

        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            TNTInOutStockInvRptQueryEntity tntInOutStockInvRptQueryEntity = this.GetTNTInOutStockInvRptQueryEntity();
            if (int.Parse(tntInOutStockInvRptQueryEntity.CurrentPage) > 0)
            {
                tntInOutStockInvRptQueryEntity.CurrentPage = (int.Parse(tntInOutStockInvRptQueryEntity.CurrentPage) - 1).ToString();
                this.BindData2ShipmentOderRptList(tntInOutStockInvRptQueryEntity);
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            TNTInOutStockInvRptQueryEntity tntInOutStockInvRptQueryEntity = this.GetTNTInOutStockInvRptQueryEntity();
            this.BindData2ShipmentOderRptList(tntInOutStockInvRptQueryEntity);
        }

        private TNTInOutStockInvRptQueryEntity GetTNTInOutStockInvRptQueryEntity()
        {
            return (base.PageQueryEntitySession as TNTInOutStockInvRptQueryEntity);
        }

        protected void GoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                TNTInOutStockInvRptQueryEntity tntInOutStockInvRptQueryEntity = this.GetTNTInOutStockInvRptQueryEntity();
                tntInOutStockInvRptQueryEntity.CurrentPage = this.PagerFooter.GoToPage.ToString();
                this.BindData2ShipmentOderRptList(tntInOutStockInvRptQueryEntity);
            }
        }

        protected void gvInOutStockInvRptList_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F15441", this.gvInOutStockInvRptList);
        }

        protected void gvInOutStockInvRptList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                if (this.hdnActionID.Value != "EXPORT")
                {
                    base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
                }
                if (((Label) e.Row.FindControl("lblBEGIN_QTY")) != null)
                {
                    this.TotalBeginQty += decimal.Parse((((Label) e.Row.FindControl("lblBEGIN_QTY")).Text != "") ? ((Label) e.Row.FindControl("lblBEGIN_QTY")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblInBound_Qty")) != null)
                {
                    this.TotalInBoundQty += decimal.Parse((((Label) e.Row.FindControl("lblInBound_Qty")).Text != "") ? ((Label) e.Row.FindControl("lblInBound_Qty")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblSCRAP_QTY")) != null)
                {
                    this.TotalScrapQty += decimal.Parse((((Label) e.Row.FindControl("lblSCRAP_QTY")).Text != "") ? ((Label) e.Row.FindControl("lblSCRAP_QTY")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblEXPIRED_QTY")) != null)
                {
                    this.TotalExpiredQty += decimal.Parse((((Label) e.Row.FindControl("lblEXPIRED_QTY")).Text != "") ? ((Label) e.Row.FindControl("lblEXPIRED_QTY")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblOutBound_Qty")) != null)
                {
                    this.TotalOutBoundQty += decimal.Parse((((Label) e.Row.FindControl("lblOutBound_Qty")).Text != "") ? ((Label) e.Row.FindControl("lblOutBound_Qty")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblInv_Qty")) != null)
                {
                    this.TotalInvQty += decimal.Parse((((Label) e.Row.FindControl("lblInv_Qty")).Text != "") ? ((Label) e.Row.FindControl("lblInv_Qty")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblOpenQty")) != null)
                {
                    this.TotalOpenQty += decimal.Parse((((Label) e.Row.FindControl("lblOpenQty")).Text != "") ? ((Label) e.Row.FindControl("lblOpenQty")).Text : "0");
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblTotalBeginQtyText.Text = base.GetPreferenceDigit(this.TotalBeginQty);
                this.lblTotalInBoundQtyText.Text = base.GetPreferenceDigit(this.TotalInBoundQty);
                this.lblTotalScrapQtyText.Text = base.GetPreferenceDigit(this.TotalScrapQty);
                this.lblTotalExpiredQtyText.Text = base.GetPreferenceDigit(this.TotalExpiredQty);
                this.lblTotalOutBoundQtyText.Text = base.GetPreferenceDigit(this.TotalOutBoundQty);
                this.lblTotalInvQtyText.Text = base.GetPreferenceDigit(this.TotalInvQty);
                this.lblTotalOpenQtyText.Text = base.GetPreferenceDigit(this.TotalOpenQty);
            }
        }

        protected void gvInOutStockInvRptList_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                TNTInOutStockInvRptQueryEntity tntInOutStockInvRptQueryEntity = this.GetTNTInOutStockInvRptQueryEntity();
                tntInOutStockInvRptQueryEntity.SortField = e.SortExpression;
                if (tntInOutStockInvRptQueryEntity.SortDirection == "ASC")
                {
                    tntInOutStockInvRptQueryEntity.SortDirection = "DESC";
                }
                else if (tntInOutStockInvRptQueryEntity.SortDirection == "DESC")
                {
                    tntInOutStockInvRptQueryEntity.SortDirection = "ASC";
                }
                this.BindData2ShipmentOderRptList(tntInOutStockInvRptQueryEntity);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void LoadData()
        {
            TNTInOutStockInvRptQueryEntity tntInOutStockInvRptQueryEntity = new TNTInOutStockInvRptQueryEntity();
            if (string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                if (this.PreviousPage != null)
                {
                    tntInOutStockInvRptQueryEntity.OWNER_ID = this.PreviousPage.OwnerID;
                    tntInOutStockInvRptQueryEntity.START_DATETIME = this.PreviousPage.StartTime;
                    tntInOutStockInvRptQueryEntity.END_DATETIME = this.PreviousPage.EndTime;
                    tntInOutStockInvRptQueryEntity.SKU_ID = this.PreviousPage.SkuID;
                    tntInOutStockInvRptQueryEntity.SKU_CLASS_ID = this.PreviousPage.SkuClassID;
                    tntInOutStockInvRptQueryEntity.DESCR = this.PreviousPage.Descr;
                    tntInOutStockInvRptQueryEntity.SKU_GROUP = this.PreviousPage.SkuGroup;
                }
                else
                {
                    tntInOutStockInvRptQueryEntity.OWNER_ID = "";
                    tntInOutStockInvRptQueryEntity.START_DATETIME = DateTime.Now.ToString();
                    tntInOutStockInvRptQueryEntity.END_DATETIME = "";
                    tntInOutStockInvRptQueryEntity.SKU_ID = "";
                    tntInOutStockInvRptQueryEntity.SKU_CLASS_ID = "";
                    tntInOutStockInvRptQueryEntity.DESCR = "";
                    tntInOutStockInvRptQueryEntity.SKU_GROUP = "";
                }
            }
            else
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            tntInOutStockInvRptQueryEntity.IsGetAll = false;
            tntInOutStockInvRptQueryEntity.CurrentPage = "0";
            tntInOutStockInvRptQueryEntity.PageSize = this.gvInOutStockInvRptList.PageSize.ToString();
            tntInOutStockInvRptQueryEntity.SortField = "SKU_CLASS_ID";
            tntInOutStockInvRptQueryEntity.SortDirection = "ASC";
            this.PagerFooter.PageSize = this.gvInOutStockInvRptList.PageSize;
            this.SetShipmentOrderRptQuery(tntInOutStockInvRptQueryEntity);
            this.BindData2ShipmentOderRptList(tntInOutStockInvRptQueryEntity);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        public void SetShipmentOrderRptQuery(TNTInOutStockInvRptQueryEntity tntInOutStockInvRptQueryEntity)
        {
            base.PageQueryEntitySession = tntInOutStockInvRptQueryEntity;
        }

        public TNTInOutStockInvRptQuery PreviousPage
        {
            get
            {
                return (TNTInOutStockInvRptQuery) base.PreviousPage;
            }
        }
    }
}

